# import matplotlib.pyplot as plt
# from skimage.data import camera
# from skimage.filters import roberts
# from skimage import io,color

# """
# 中文显示工具函数
# """
# def set_ch():
#     from pylab import mpl
#     mpl.rcParams['font.sans-serif']=['FangSong']
#     mpl.rcParams['axes.unicode_minus']=False
# set_ch()

# # image = camera()
# image = io.imread('lena.bmp') 
# image=color.rgb2gray(image)
# edge_roberts = roberts(image)
# fig, ax = plt.subplots(ncols=2, sharex=True, sharey=True,
#                     figsize=(8, 4))
# ax[0].imshow(image, cmap=plt.cm.gray)
# ax[0].set_title('原始图像')
# ax[1].imshow(edge_roberts, cmap=plt.cm.gray)
# ax[1].set_title('Roberts 边缘检测')
# for a in ax:
#     a.axis('off')
# plt.tight_layout()
# plt.show()

# import matplotlib.pyplot as plt
# from skimage.data import camera
# from skimage.filters import sobel,sobel_v,sobel_h
# from skimage import io,color
# """
# 中文显示工具函数
# """
# def set_ch():
#     from pylab import mpl
#     mpl.rcParams['font.sans-serif']=['FangSong']
#     mpl.rcParams['axes.unicode_minus']=False
# set_ch()

# # image = camera()
# image = io.imread('lena.bmp') 
# image=color.rgb2gray(image)
# edge_sobel = sobel(image)
# edge_sobel_v=sobel_v(image)
# edge_sobel_h=sobel_h(image)

# fig, ax = plt.subplots(ncols=2, nrows=2,sharex=True, sharey=True,
#                     figsize=(8, 4))
# ax[0,0].imshow(image, cmap=plt.cm.gray)
# ax[0,0].set_title('原始图像')

# ax[0,1].imshow(edge_sobel, cmap=plt.cm.gray)
# ax[0,1].set_title('Sobel 边缘检测')


# ax[1,0].imshow(edge_sobel_v, cmap=plt.cm.gray)
# ax[1,0].set_title('Sobel 垂直边缘检测')

# ax[1,1].imshow(edge_sobel_h, cmap=plt.cm.gray)
# ax[1,1].set_title('Sobel 水平边缘检测')

# for a in ax:
#     for j in a:
#         j.axis('off')

# plt.tight_layout()
# plt.show()

# import matplotlib.pyplot as plt
# from skimage.data import camera,coffee
# from skimage.filters import laplace
# from skimage import io,color
# """
# 中文显示工具函数
# """
# def set_ch():
#     from pylab import mpl
#     mpl.rcParams['font.sans-serif']=['FangSong']
#     mpl.rcParams['axes.unicode_minus']=False
# set_ch()

# # image = camera()
# image = io.imread('lena.bmp') 
# image=color.rgb2gray(image)
# edge_laplace = laplace(image)
# image1=coffee()
# edge_laplace1=laplace(image1)

# fig, ax = plt.subplots(ncols=2,nrows=2,sharex=True, sharey=True,
#                     figsize=(8, 6))
# ax[0,0].imshow(image, cmap=plt.cm.gray)
# ax[0,0].set_title('原始图像')

# ax[0,1].imshow(edge_laplace, cmap=plt.cm.gray)
# ax[0,1].set_title('Laplace 边缘检测')

# ax[1,0].imshow(image1)
# ax[1,0].set_title('原始图像')

# ax[1,1].imshow(edge_laplace1)
# ax[1,1].set_title('Laplace 边缘检测')

# for a in ax:
#     for j in a:
#         j.axis('off')

# plt.tight_layout()
# plt.show()
# import matplotlib.pyplot as plt
# from skimage.data import camera,coffee
# from skimage.filters import laplace,gaussian
# from skimage import io,color
# """
# 中文显示工具函数
# """
# def set_ch():
#     from pylab import mpl
#     mpl.rcParams['font.sans-serif']=['FangSong']
#     mpl.rcParams['axes.unicode_minus']=False
# set_ch()

# # image = camera()
# image = io.imread('lena.bmp') 
# image=color.rgb2gray(image)
# edge_laplace = laplace(image)

# gaussian_image=gaussian(image)

# edge_LoG=laplace(gaussian_image)

# fig, ax = plt.subplots(ncols=2,nrows=2,sharex=True, sharey=True,
#                     figsize=(8, 6))
# ax[0,0].imshow(image, cmap=plt.cm.gray)
# ax[0,0].set_title('原始图像')

# ax[0,1].imshow(edge_laplace, cmap=plt.cm.gray)
# ax[0,1].set_title('Laplace 边缘检测')

# ax[1,0].imshow(gaussian_image,cmap=plt.cm.gray)
# ax[1,0].set_title('高斯平滑后图像')

# ax[1,1].imshow(edge_LoG,cmap=plt.cm.gray)
# ax[1,1].set_title('LoG 边缘检测')

# for a in ax:
#     for j in a:
#         j.axis('off')

# plt.tight_layout()
# plt.show()


import matplotlib.pyplot as plt
from skimage import io, color, filters

# 中文显示工具函数
def set_ch():
    from pylab import mpl
    mpl.rcParams['font.sans-serif'] = ['FangSong']
    mpl.rcParams['axes.unicode_minus'] = False
set_ch()

# 读取 Lena 图像并转换为灰度图像
image = io.imread('lena.bmp')
gray_image = color.rgb2gray(image)

# Roberts 边缘检测
edge_roberts = filters.roberts(gray_image)

# Sobel 边缘检测
edge_sobel = filters.sobel(gray_image)

# Laplace 边缘检测
edge_laplace = filters.laplace(gray_image)

# 高斯-拉普拉斯（LoG）边缘检测
gaussian_image = filters.gaussian(gray_image)
edge_LoG = filters.laplace(gaussian_image)

# 创建一个 figure 窗体，用于显示所有边缘检测结果
fig, axs = plt.subplots(2, 3, figsize=(15, 10))

# 显示原始图像
axs[0, 0].imshow(gray_image, cmap='gray')
axs[0, 0].set_title('原始图像')
axs[0, 0].axis('off')

# 显示 Roberts 边缘检测
axs[0, 1].imshow(edge_roberts, cmap='gray')
axs[0, 1].set_title('Roberts 边缘检测')
axs[0, 1].axis('off')

# 显示 Sobel 边缘检测
axs[0, 2].imshow(edge_sobel, cmap='gray')
axs[0, 2].set_title('Sobel 边缘检测')
axs[0, 2].axis('off')

# 显示 Laplace 边缘检测
axs[1, 0].imshow(edge_laplace, cmap='gray')
axs[1, 0].set_title('Laplace 边缘检测')
axs[1, 0].axis('off')

# 显示高斯平滑后图像
axs[1, 1].imshow(gaussian_image, cmap='gray')
axs[1, 1].set_title('高斯平滑后图像')
axs[1, 1].axis('off')

# 显示高斯-拉普拉斯（LoG）边缘检测
axs[1, 2].imshow(edge_LoG, cmap='gray')
axs[1, 2].set_title('LoG 边缘检测')
axs[1, 2].axis('off')

# 调整布局并显示所有图像
plt.tight_layout()
plt.show()
